# coding=utf-8
from flask import Flask, request
from flask_cors import CORS
import json
import requests

app = Flask(__name__)
CORS(app, resources = r'/*')

@app.route('/api/ai/test', methods=['POST'])
def genAudio():
    tishici = request.json.get('tishici')
    text = request.json.get('text')
    url = "https://api.deepseek.com/chat/completions"
    payload = json.dumps({
    "messages": [
        {
        "content": tishici,
        "role": "system"
        },
        {
        "content": text,
        "role": "user"
        }
    ],
    "model": "deepseek-chat",
    "temperature": 0.7
    })
    headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': 'Bearer sk-b82c34de37154d3180a814d774aa1d7e'
    }

    response = requests.request("POST", url, headers=headers, data=payload)
    responseData = response.json()
    data = {
        'content' : responseData['choices'][0]['message']['content'],
        # 'reasoning_content': responseData['choices'][0]['message']['reasoning_content']
    }
    return json.dumps({'message':'操作成功', 'code':200, 'result':data})

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0',port=8888)
